package com.finalcial.service.impl;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



import com.finalcial.dao.OtherDao;
import com.finalcial.po.Datas;
import com.finalcial.po.ExcelBean;

import com.finalcial.service.ExcelService;
import com.finalcial.util.ExcelUtil;
import com.finalcial.util.ExportExcel;



@Service
public class ExcelServiceImpl implements ExcelService{
	@Autowired
	private OtherDao otherDao;
	
	@Override
	public XSSFWorkbook exportExcelInfo(String reimbursementId) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, IntrospectionException, ParseException {
		//内部人信息
		/*List<Map<String, Object>> listOther = declarationInformationService.getOtherInformation(reimbursementId);
		 for (Map<String, Object> m : listOther)
		    {
		      for (String k : m.keySet())
		      {
		        System.out.println(k + " : " + m.get(k));
		      }

		    }*/
		
		List<Datas> listOther = otherDao.getOtherInformationByExpore(reimbursementId);
		
		
	    List<com.finalcial.po.ExcelBean> excel=new ArrayList<>();  
	    Map<Integer,List<ExcelBean>> map=new LinkedHashMap<>();  
	    XSSFWorkbook xssfWorkbook=null;  
	    //设置标题栏  
	    excel.add(new ExcelBean("序号","number",0));  
	    excel.add(new ExcelBean("姓名" ,"name",0));  
	    excel.add(new ExcelBean("部门","department",0));  
	    excel.add(new ExcelBean("用户编号","userId",0));  
	    excel.add(new ExcelBean("收款方式","collection",0));  
	    excel.add(new ExcelBean("公司名称","companyName",0));  
	    excel.add(new ExcelBean("开户行","bankName",0));  
	    excel.add(new ExcelBean("银行卡号","bankNumber",0));  
	    excel.add(new ExcelBean("金额","money",0));  
	    
	    map.put(0, excel);  
	    String sheetName = "内部人信息"; 
	    //调用ExcelUtil的方法  
	    xssfWorkbook = ExcelUtil.createExcelFile(Datas.class, listOther, map, sheetName);
	    		//(Datas.class, listOther, map, sheetName);
	    return xssfWorkbook;
	}

	@Override
	public void exportExcel(String number,String name,String department,String collection,String companyName,String bankName,String userId,String bankNumber,String money) {
		/**模拟数据开始*/
		/*List<Employee> staffs = new ArrayList<Employee>();
	    for (int i = 0; i < 65532; i++) {
	      Employee staff = new Employee(i, i+"group", 1900+i, 12, 25, 2500+i);
	      staffs.add(staff);
	    }
	    Map<String, String> titleMap = new LinkedHashMap<String,String>();
	    titleMap.put("name", "姓名");
	    titleMap.put("clazz", "组号");
	    titleMap.put("year", "年份");
	    titleMap.put("month", "月份");
	    titleMap.put("day", "天");
	    titleMap.put("salary", "薪资");
	    String sheetName = "内部人信息";
	    */
		/**模拟数据结束*/
		 
	/*  List<Datas> datas = new ArrayList<Datas>();
	    datas = otherDao.getOtherInformationByExpore(reimbursementId);*/
	    
		 
		List<Datas> staffs = new ArrayList<Datas>();
	    Datas datas = new Datas(number, name, department, collection, companyName, bankName, userId, bankNumber, money);
	 	staffs.add(datas);
	 	
	 	Map<String, String> titleMap = new LinkedHashMap<String,String>();
	    titleMap.put("name", "姓名");
	    titleMap.put("department", "部门");
	    titleMap.put("collection", "收款类型");
	    titleMap.put("companyName", "公司名称");
	    titleMap.put("bankName", "开户行");
	    titleMap.put("userId", "员工编号");
	    titleMap.put("bankNumber", "银行账号");
	    titleMap.put("money", "金额");
	    
	    String sheetName = "内部人信息";
	    
	    System.out.println("start导出");
	    long start = System.currentTimeMillis();
	    ExportExcel.excelExport(staffs, titleMap, sheetName);
	    long end = System.currentTimeMillis();
	    System.out.println("end导出");
	    System.out.println("耗时："+(end-start)+"ms");
	  }
		
	}
	
	
	

